const tree = [
  {
    title: '0-0',
    key: '0-0',
    children: [
      {
        title: '0-0-0',
        key: '0-0-0',
        children: [
          { title: '0-0-0-0', key: '0-0-0-0' },
          { title: '0-0-0-1', key: '0-0-0-1' },
          { title: '0-0-0-2', key: '0-0-0-2' }
        ]
      }
    ]
  },
  {
    title: '0-1',
    key: '0-1',
    children: [
      { title: '0-1-0-0', key: '0-1-0-0' },
      { title: '0-1-0-1', key: '0-1-0-1' },
      { title: '0-1-0-2', key: '0-1-0-2' }
    ]
  },
  {
    title: '0-2',
    key: '0-2'
  }
]
/**
 * 查找叶子节点
 * @param {*} tree 树结构数据
 * @param {*} val 查找的值
 * @param {*} key 节点属性key值，默认为id
 * @returns 叶子节点对象
 */
const findLeaf = (tree, val, key = 'id') => {
  for (const item of tree) {
    if (item[key] === val) return item
    if ('children' in item) {
      const result = findLeaf(item.children, val, key)
      if (result) return result
    }
  }
  return null
}
const node = findLeaf(tree, '0-1-0-0', 'key')
console.log(node)
